<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    .active {
      color: red
    }
  </style>
</head>
<body>
<!--作业需求：点击列表中的哪一项，那么该项的文字变成红色-->
<div id="app">
  <ul v-for="(movie, index) in movies">
    <li :class="getClasses(index)" @click="click(index)">{{movie}}</li>
  </ul>
</div>

<script src="../js/vue.js"></script>
<script>
  const app = new Vue({
    el: '#app',
    data: {
      movies: ['火影忍者', '海贼王', '游戏王'],
      className: 'active',
      currentIndex: 0,
    },
    methods: {
      click: function (index) {
        this.currentIndex = index;
      },
      getClasses: function (index) {
        if (this.currentIndex == index) {
          return [this.className];
        }
        return []
      }
    }
  })
</script>
</body>
</html>
